package main

import (
	"log"

	"gin-quickstart/internal/api"
	"gin-quickstart/internal/database"

	"github.com/gin-gonic/gin"
)

func main() {
	// 初始化数据库连接
	err := database.InitDatabase("configs/config.json")
	if err != nil {
		log.Fatalf("Failed to initialize database: %v", err)
	}
	defer func() {
		if err := database.CloseDatabase(); err != nil {
			log.Printf("Error closing database: %v", err)
		}
	}()

	// 创建Gin路由
	router := gin.Default()

	// 设置路由
	api.SetupRoutes(router)

	// 启动服务器
	if err := router.Run(); err != nil {
		log.Fatalf("Failed to start server: %v", err)
	}
}